//
//  AppDefine.h
//  powercloudneutral
//
//  Created by Peng on 2018/5/4.
//  Copyright © 2018年 Peng. All rights reserved.
//

#ifndef AppDefine_h
#define AppDefine_h


//1.获取屏幕宽度与高度
//需要横屏或者竖屏，获取屏幕宽度与高度
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000 // 当前Xcode支持iOS8及以上

#define LFSCREEN_WIDTH ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.width)
#define LFSCREENH_HEIGHT ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale:[UIScreen mainScreen].bounds.size.height)
#define LFSCREEN_SIZE ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)]?CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale):[UIScreen mainScreen].bounds.size)
#else
#define LFSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define LFSCREENH_HEIGHT [UIScreen mainScreen].bounds.size.height
#define LFSCREEN_SIZE [UIScreen mainScreen].bounds.size
#endif
#define  LFSCREEN_iPhone6Weight 375.0
#define  LFSCREEN_iPhone6Height 667.0
#define  LFSCREEN_BasicHeight (1/LFSCREEN_iPhone6Height*LFSCREENH_HEIGHT)
#define  LFSCREEN_BasicWidth (1/LFSCREEN_iPhone6Weight*LFSCREEN_WIDTH)

#define IsNilOrNull(_ref)   (((_ref) == nil) || ([(_ref) isEqual:[NSNull null]]) || ([(_ref) isEqual:[NSNull class]]))

#define VALIDATE_STRING(str) (IsNilOrNull(str) ? @"" : str)

//2.获取通知中心
#define LFNotificationCenter [NSNotificationCenter defaultCenter]

//3.设置随机颜色
#define LFRandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1.0]
#define RGBA(R, G, B, A) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:A]

#define RGB(R, G, B) [UIColor colorWithRed:((R) / 255.0f) green:((G) / 255.0f) blue:((B) / 255.0f) alpha:1.0f]
//4.设置RGB颜色/设置RGBA颜色
#define LFRGBColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
#define LFRGBAColor(r, g, b, a) [UIColor colorWithRed:(r)/255.0 green:(r)/255.0 blue:(r)/255.0 alpha:a]

/** 16进制颜色 @param Color 颜色值 */
#define LFHexColor(Color) [UIColor colorWithHexString:(Color)]


//6.弱引用/强引用
#define LFWeakSelf(type)  __weak typeof(type) weak##type = type;
#define LFStrongSelf(type)  __strong typeof(type) type = weak##type;

//7.设置 view 圆角和边框
#define LFViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]]

//8.判断当前的iPhone设备/系统版本

#define LFStatusBarHeight ([[UIApplication sharedApplication] statusBarFrame].size.height)

//判断是否是ipad
#define LFisPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

#define LFiPhone4 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)

// 判断是否为 iPhone 5SE
#define LFiPhone5SE [[UIScreen mainScreen] bounds].size.width == 320.0f && [[UIScreen mainScreen] bounds].size.height == 568.0f

// 判断是否为iPhone 6/6s
#define LFiPhone6_6s [[UIScreen mainScreen] bounds].size.width == 375.0f && [[UIScreen mainScreen] bounds].size.height == 667.0f

// 判断是否为iPhone 6Plus/6sPlus
#define LFiPhone6Plus_6sPlus [[UIScreen mainScreen] bounds].size.width == 414.0f && [[UIScreen mainScreen] bounds].size.height == 736.0f

//判断iPhoneX
#define LFiPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !LFisPad : NO)
//判断iPHoneXr
#define LFiPhone_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !LFisPad : NO)
//判断iPhoneXs
#define LFiPhone_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !LFisPad : NO)
//判断iPhoneXs Max
#define LFiPhone_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !LFisPad : NO)
//判断iPhoneX 系列
#define LFiPhoneXSeries (LFStatusBarHeight >= 44.0f ? YES : NO)

#define kIsBangsScreen ({\
    BOOL isBangsScreen = NO; \
    if (@available(iOS 11.0, *)) { \
    UIWindow *window = [[UIApplication sharedApplication].windows firstObject]; \
    isBangsScreen = window.safeAreaInsets.bottom > 0; \
    } \
    isBangsScreen; \
})

//iPhoneX系列
#define LFSafeAreaTopHeight (LFiPhoneXSeries ? 88.0 : 64.0)
#define LFSafeAreaBottomHeight (LFiPhoneXSeries ? 34 : 0)
#define LFTopEdgeInset (LFiPhoneXSeries ? 44.0 : 20.0)

#define LFTopEdgeInset_x (LFiPhoneXSeries ? 24 : 0)

//获取系统版本
#define LF_IOS_SYSTEM_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]

// ios7
#define LF_IOS7_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)

//判断 iOS 8 或更高的系统版本
#define LF_IOS_VERSION_8_OR_LATER (([[[UIDevice currentDevice] systemVersion] floatValue] >=8.0)? (YES):(NO))

//9.判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//10.沙盒目录文件
//获取temp
#define LFkPathTemp NSTemporaryDirectory()

//获取沙盒 Document
#define LFkPathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]

//获取沙盒 Cache
#define LFkPathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]

#define LocalizedString(key) \
[LocationFile getLocationStringTableForKey:key value:@"" table:@""]

//11. 获取APP相关信息
/**
 获取App名称
 @return App名称 string类型
 */
#define LFkAppName [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]

/**
 获取App版本号
 @return App版本号 string类型
 */
#define LFkAppVersion [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"]



#endif
